package com.thinkgem.jeesite.modules.guobo.web;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.modules.guobo.entity.ExhHall;
import com.thinkgem.jeesite.modules.guobo.entity.ExhStockReport;
import com.thinkgem.jeesite.modules.guobo.service.AssetService;
import com.thinkgem.jeesite.modules.guobo.service.ExhHallService;

/**
 * 
 * @author 展馆存量查询
 *
 */
@Controller
@RequestMapping(value = "${adminPath}/guobo/exhstockreport")
public class ExhStockReportController extends BaseController {
	
	@Autowired
	private AssetService assetService;
	
	@Autowired
	private ExhHallService exhHallService;
	
	/**
	 * 非固定资产报表
	 * @param exhStockReport
	 * @param request
	 * @param choiceHall
	 * @param response
	 * @param model
	 * @return
	 */
	@RequiresPermissions("guobo:exhstockreport:view")
	@RequestMapping(value = {"list", ""})
	public String list(ExhStockReport exhStockReport, HttpServletRequest request,String[] choiceHall,  HttpServletResponse response, Model model) {
		Map<String,Object> param = new HashMap<String,Object>();
		param.put("code", (exhStockReport.getAssetCode()==null)?null:exhStockReport.getAssetCode());
		param.put("name", (exhStockReport.getAssetName()==null)?null:exhStockReport.getAssetName());
		param.put("spec", exhStockReport.getAssetSpec());
		param.put("model", exhStockReport.getAssetModle());
		String exhIds = "";		
		List<ExhHall> exhHalls = new ArrayList<ExhHall>();
		if(choiceHall==null || choiceHall.length==0){
			 List<ExhHall> temps = exhHallService.findAllExhHall();
			 exhHalls.addAll(temps);
		}else{		
			for (String id : choiceHall) {
				exhHalls.add(exhHallService.get(id));
				exhIds = exhIds+","+id;
			}
		}
		if(exhIds!=""){
			param.put("exhIds", exhIds.subSequence(1, exhIds.length()));
		}else{
			param.put("exhIds", exhIds);
		}		
		List<ExhHall> allExhHalls = exhHallService.findAllExhHall();
		model.addAttribute("allExhHalls", allExhHalls);
		Page<ExhStockReport> page = assetService.findExhStockReport(new Page<ExhStockReport>(request, response), exhStockReport, param); 
		model.addAttribute("page", page);
		model.addAttribute("exhStockReport", exhStockReport);
		model.addAttribute("exhHalls", exhHalls);
		return "modules/guobo/exhStockReport";
	}
	
	/**
	 * 固定资产报表
	 * @param exhStockReport
	 * @param request
	 * @param choiceHall
	 * @param response
	 * @param model
	 * @return
	 */
	@RequiresPermissions("guobo:exhstockreport:view")
	@RequestMapping(value = {"fixedAssetslist", ""})
	public String fixedAssetslist(ExhStockReport exhStockReport, HttpServletRequest request,String[] choiceHall,  HttpServletResponse response, Model model) {
		Map<String,Object> param = new HashMap<String,Object>();
		param.put("code", (exhStockReport.getAssetCode()==null)?null:exhStockReport.getAssetCode());
		param.put("name", (exhStockReport.getAssetName()==null)?null:exhStockReport.getAssetName());
		param.put("spec", exhStockReport.getAssetSpec());
		param.put("model", exhStockReport.getAssetModle());
		String exhIds = "";		
		List<ExhHall> exhHalls = new ArrayList<ExhHall>();
		if(choiceHall==null || choiceHall.length==0){
			 List<ExhHall> temps = exhHallService.findAllExhHall();
			 exhHalls.addAll(temps);
		}else{		
			for (String id : choiceHall) {
				exhHalls.add(exhHallService.get(id));
				exhIds = exhIds+","+id;
			}
		}
		if(exhIds!=""){
			param.put("exhIds", exhIds.subSequence(1, exhIds.length()));
		}else{
			param.put("exhIds", exhIds);
		}		
		List<ExhHall> allExhHalls = exhHallService.findAllExhHall();
		model.addAttribute("allExhHalls", allExhHalls);
		Page<ExhStockReport> page = assetService.findFixedAssetsExhStockReport(new Page<ExhStockReport>(request, response), exhStockReport, param); 
		model.addAttribute("page", page);
		model.addAttribute("exhStockReport", exhStockReport);
		model.addAttribute("exhHalls", exhHalls);
		return "modules/guobo/fixedAssetsExhStockReport";
	}
}
